home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
optivc32
/
cfmath.h
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-06
|
16KB
|
468 lines
/* CFMATH.H
Complex library for the languages C and C++.
This header file contains all definitions for
single-precision complex numbers (complex float).
Copyright (C) 1996-1999 Martin Sander
Address of the author:
Dr. Martin Sander Software Dev.
Sertuernerstr. 11
D-37085 Goettingen
Germany
MartinSander@Bigfoot.com
http://www.optivec.com
*/
#ifndef __CFMATH_H
#define __CFMATH_H
#if !defined( _CMATH_DEFS )
#ifdef __BORLANDC__
#pragma option -a-
#else /* Visual C++ */
#pragma pack( push,1 )
#endif /* avoid insertion of dummy bytes */
typedef struct {float Re, Im;} fComplex;
typedef struct {double Re, Im;} dComplex;
#ifdef __BORLANDC__
typedef long double extended;
typedef struct {extended Re, Im;} eComplex;
#pragma option -a.
#else /* Visual C++ */
typedef double extended; /* Visual C++ does not support
80-bit IEEE numbers. So make
extended equal to double */
typedef dComplex eComplex;
#pragma pack( pop )
#endif /* restore default data packing */
typedef fComplex fcomplex;
typedef dComplex dcomplex;
typedef eComplex ecomplex; // tolerate all-lower case
#define _CMATH_DEFS
#endif
#ifdef __BORLANDC__
#include <_defs.h>
#if defined __TINY || defined __SMALL__ || defined __MEDIUM__
#if defined(_RTLDLL) || defined(_CLASSDLL)
#error Must use static BC Runtime Library with OptiVec and CMATH in models TINY, SMALL, MEDIUM
#endif
#define _VFAR near /* even in case of DS!=SS */
#elif defined __FLAT__
#define _VFAR
#else
#define _VFAR far
#endif
#if (__BORLANDC__ >= 0x450)
#define __cmf _RTLENTRY _EXPFUNC
#else
#define __cmf _Cdecl _FARFUNC
#endif
#else /* Visual C++, Optima++ */
#define _VFAR
#define __cmf __cdecl
#endif
#define _VFARC const _VFAR
/* first the constructors: */
#ifdef __cplusplus
/* since fComplex is declared as a struct instead of a class,
the constructor cannot get the name "fComplex" here. */
#ifndef _FCPLX_DEFINED
inline fComplex __cmf fcplx( float __ReVal )
{ fComplex Result;
Result.Re = __ReVal;
Result.Im = 0.0f;
return Result;
}
// down-conversions from double and extended precision
// (with OVERFLOW error handling):
fComplex __cmf fcplx( dComplex __zd );
#if defined __COMPLEX_H
fComplex __cmf fcplx( complex __z );
#endif
#ifdef __BORLANDC__
fComplex __cmf fcplx( eComplex __ze );
#endif
#define _FCPLX_DEFINED
#endif // _FCPLX_DEFINED
#endif
/* basic form of constructor for C and C++ : */
fComplex __cmf fcplx( float __ReVal, float __ImVal);
/* down-conversion with OVERFLOW-handling: */
#if !defined __NEWCPLX_H
#if defined __cplusplus
extern "C" {
#endif
fComplex __cmf cdtocf( dComplex __zd );
fComplex __cmf cetocf( eComplex __ze );
#if defined __cplusplus
}
#endif
#endif
/* Basic complex operations. They are defined both
for C and C++. However, for C++ you may as well use the
overloaded operators and functions defined further below. */
#define cf_real( z ) (z).Re
#define cf_imag( z ) (z).Im
#if defined __cplusplus && !defined _CMATH_CLASSDEFS
extern "C" { // the following functions cannot be "extern C",
#endif // if fComplex identical with complex<float>
fComplex __cmf cf_neg( fComplex __z );
fComplex __cmf cf_conj( fComplex __z );
#ifdef __cplusplus // even if _CMATH_CLASSDEFS
extern "C" float __cmf cf_norm( fComplex __z );
extern "C" float __cmf cf_arg( fComplex __z );
#else
float __cmf cf_norm( fComplex __z );
float __cmf cf_arg( fComplex __z );
#endif
fComplex __cmf cf_polar( float __mag, float __angle );
fComplex __cmf cf_add( fComplex __x, fComplex __y );
fComplex __cmf cf_addRe( fComplex __x, float __yRe );
fComplex __cmf cf_sub( fComplex __x, fComplex __y );
fComplex __cmf cf_subRe( fComplex __x, float __yRe ); /* x - yRe */
fComplex __cmf cf_subrRe( fComplex __x, float __yRe ); /* yRe - x */
fComplex __cmf cf_mul( fComplex __x, fComplex __y );
fComplex __cmf cf_mulRe( fComplex __x, float __yRe );
fComplex __cmf cf_div( fComplex __x, fComplex __y );
fComplex __cmf cf_divRe( fComplex __x, float __yRe ); /* x / yRe */
fComplex __cmf cf_divrRe( fComplex __x, float __yRe ); /* yRe / x */
/* mathematical functions with error handling through _matherr: */
#ifdef __cplusplus // even if _CMATH_CLASSDEFS
extern "C" float __cmf cf_abs( fComplex __z );
#else
float __cmf cf_abs( fComplex __z );
#endif
fComplex __cmf cf_acos( fComplex __z );
fComplex __cmf cf_asin( fComplex __z );
fComplex __cmf cf_atan( fComplex __z );
fComplex __cmf cf_cos( fComplex __z );
fComplex __cmf cf_cosh( fComplex __z );
fComplex __cmf cf_cubic( fComplex __z ); /* raise to the third power */
fComplex __cmf cf_exp( fComplex __z );
fComplex __cmf cf_inv( fComplex __z ); /* 1.0 / z */
fComplex __cmf cf_ipow( fComplex __z, int __exponent );
/* raise z to integer power */
fComplex __cmf cf_ln( fComplex __z );
fComplex __cmf cf_log( fComplex __z ); /* same as cf_ln */
fComplex __cmf cf_log2( fComplex __z );
fComplex __cmf cf_log10( fComplex __z );
fComplex __cmf cf_pow( fComplex __base, fComplex __exponent );
fComplex __cmf cf_powReBase( float __base, fComplex __exponent ); /* power of real base */
fComplex __cmf cf_powReExpo( fComplex __base, float __exponent ); /* raise z to real power */
/* for integer exponents, use cf_ipow ! */
fComplex __cmf cf_quartic( fComplex __z ); /* raise to the fourth power */
fComplex __cmf cf_sin( fComplex __z );
fComplex __cmf cf_sinh( fComplex __z );
fComplex __cmf cf_square( fComplex __z );
fComplex __cmf cf_sqrt( fComplex __z );
fComplex __cmf cf_tan( fComplex __z );
fComplex __cmf cf_tanh( fComplex __z );
#if defined __cplusplus && !defined _CMATH_CLASSDEFS
} // end of the extern "C" statement
#endif
#if defined __cplusplus && !defined __STD_COMPLEX && !defined __NEWCPLX_H
/* in addition to the basic operations defined above for C,
here is the same complete set of overloaded operators and
functions as offered by <newcplx.h> for the complex classes. */
inline float real( fComplex _VFARC & __z )
{
return __z.Re;
}
inline float imag( fComplex _VFARC & __z )
{
return __z.Im;
}
inline fComplex neg( fComplex _VFARC & __z1 )
{ fComplex Result;
Result.Re = -__z1.Re;
Result.Im = -__z1.Im;
return Result;
}
inline fComplex conj( fComplex _VFARC & __z)
{ fComplex Result;
Result.Re = __z.Re;
Result.Im = -__z.Im;
return Result;
}
float __cmf norm( fComplex __z );
float __cmf arg( fComplex __z );
fComplex __cmf polar( float Mag, float Angle );
// unary operators:
inline fComplex _VFAR & operator +( fComplex _VFAR & __z1 )
{
return __z1;
}
inline fComplex operator -( fComplex _VFARC & __z1 )
{ fComplex Result;
Result.Re = -__z1.Re;
Result.Im = -__z1.Im;
return Result;
}
// binary operators:
inline fComplex operator +( fComplex _VFARC & __z1, fComplex _VFARC & __z2 )
{ fComplex Result;
Result.Re = __z1.Re + __z2.Re;
Result.Im = __z1.Im + __z2.Im;
return Result;
}
inline fComplex operator +( fComplex _VFARC & __z1, float __z2Re )
{ fComplex Result;
Result.Re = __z1.Re + __z2Re;
Result.Im = __z1.Im;
return Result;
}
inline fComplex operator +( float __z1Re, fComplex _VFARC & __z2 )
{ fCompl